package com.fzg.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fzg.common.enums.ResponseWrapper;
import com.fzg.common.tool.JwtUtil;
import com.fzg.entity.UserGuanzhu;
import com.fzg.mapper.UserGuanzhuMapper;
import com.fzg.service.UserGuanzhuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author fzg
 * @since 2022-06-22
 */
@Service
public class UserGuanzhuServiceImpl extends ServiceImpl<UserGuanzhuMapper, UserGuanzhu> implements UserGuanzhuService {

    @Autowired
    private UserGuanzhuMapper userGuanzhuMapper;


    /**
     * 关注
     *
     * @param request 参数
     * @param userAid 参数
     */
    @Override
    public ResponseWrapper concernUser(HttpServletRequest request, Integer userAid) {
        userGuanzhuMapper.insert(new UserGuanzhu(){{
            setGuanzhuUserAid(JwtUtil.getTokenId(request.getHeader("token")));
            setBeiguanzhuUserAid(userAid);
        }});
        return null;
    }

    /**
     * 取消关注
     *
     * @param request 参数
     * @param userAid 参数
     */
    @Override
    public ResponseWrapper cancelConcernUser(HttpServletRequest request, Integer userAid) {
        userGuanzhuMapper.delete(new LambdaQueryWrapper<UserGuanzhu>()
                .eq(UserGuanzhu::getGuanzhuUserAid,JwtUtil.getTokenId(request.getHeader("token")))
                .eq(UserGuanzhu::getBeiguanzhuUserAid,userAid)
        );
        return null;
    }
}
